package com.jiaxue.admin.handler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jiaxue.admin.util.SysContext;

public class LogAdvice {
	private static final Logger LOG = LoggerFactory.getLogger(LogAdvice.class);
    HttpServletRequest request;  
    HttpServletResponse response;  
    
	public Object afterReturning(ProceedingJoinPoint joinPoint) throws Throwable {
		LOG.info("---***********BEGIN************---");
        request = SysContext.getRequest();  
        response = SysContext.getResponse(); 
        String callbackvalue=null;
        LOG.info("---请求URL:"+request.getRequestURL());
        LOG.info("---请求RemoteAddr:"+request.getRemoteAddr());
        //System.out.println("---请求方法:"+request.getMethod());
        LOG.info("---请求QueryString:"+request.getQueryString());
       /* Enumeration parameterNames = request.getParameterNames();
        while(parameterNames.hasMoreElements()){
        	String param = parameterNames.nextElement().toString();
        	if("callback".equalsIgnoreCase(param)){
        		callbackvalue = request.getParameter(param);
        	}
        }
        Object retVal = joinPoint.proceed();

		Method method = ((MethodSignature)joinPoint.getSignature()).getMethod();
		JSONP annotation = method.getAnnotation(JSONP.class);*/
		/*if(annotation!=null&&callbackvalue!=null&&!"".equalsIgnoreCase(callbackvalue)){
			retVal=new JSONPObject(callbackvalue, retVal);
			return retVal;
		}*/
        Object proceed = joinPoint.proceed();
        LOG.info("---**********END*************---");
		return proceed;
	}
	
	public void afterThrow(JoinPoint jp,Exception e){
		e.printStackTrace();
		LOG.error(e.getMessage());
	}
	
}
